﻿
using NetCore.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetCore.BLL
{
    public class CommonHelper
    {

        /// <summary>
        /// 系统所有页面列表
        /// </summary>
        public static List<PageEntity> SystemPageEntities { get; set; }

        /// <summary>
        /// 初始化页面
        /// </summary>
        /// <param name="lstMvc">mvc dll引用路径</param>
        public static void InitPages()
        {
            List<MenuPageAttribute> routePages = ControllerHelper.GetController();///获取所有页面列表
            if (routePages != null && routePages.Count > 0)
            {
                List<PageEntity> entities = new List<PageEntity>();
                foreach (var item in routePages)
                {
                    entities.Add(new PageEntity
                    {
                        PageId = item.PageId,
                        LocalName = item.LocalName,
                        ActionName = item.MenuName,
                        RouteUrl = item.RouteUrl,
                        IsAdmin = item.IsAdmin,
                        IsDisplay = item.IsDispay,
                        IsMenu = item.IsMenu,
                        ParentId = item.ParentId,
                        OrderNum = item.OrderNum,
                        LstActions=item.PageActions,
                        Icon=item.Icon
                    });
                }
                if (entities != null)
                {
                    SystemPageEntities = entities.OrderBy(x => x.OrderNum).ToList();
                }
             

            }
        }

        // <summary>
        /// 初始化页面
        /// </summary>
        /// <param name="lstMvc">mvc dll引用路径</param>
        public static void InitApi(List<string> lstApi)
        {
            List<MenuPageAttribute> routePages = ControllerHelper.GetApiController(lstApi);///获取所有页面列表
            if (routePages != null && routePages.Count > 0)
            {
                List<PageEntity> entities = new List<PageEntity>();
                foreach (var item in routePages)
                {
                    entities.Add(new PageEntity
                    {
                        PageId = item.PageId,
                        LocalName = item.LocalName,
                        ActionName = item.MenuName,
                        RouteUrl = item.RouteUrl,
                        IsAdmin = item.IsAdmin,
                        IsDisplay = item.IsDispay,
                        IsMenu = item.IsMenu,
                        ParentId = item.ParentId,
                        OrderNum = item.OrderNum,
                        LstActions = item.PageActions,
                        Icon = item.Icon,
                        IsApi=item.IsApi
                    });
                }
                if (entities != null)
                {
                    SystemPageEntities = entities.OrderBy(x => x.OrderNum).ToList();
                }


            }
        }
    }
}
